﻿<UserControl x:Class="AmazedSaint.Vingy.SearchControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:vsfx="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.10.0"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"
             Name="MyToolWindow"
             Background="{DynamicResource {x:Static vsfx:VsBrushes.ToolWindowBackgroundKey}}">
    <UserControl.Resources>

    </UserControl.Resources>
    <Grid Background="{DynamicResource {x:Static vsfx:VsBrushes.ToolWindowBackgroundKey}}">

        <Border Background="{DynamicResource {x:Static vsfx:VsBrushes.ToolWindowBackgroundKey}}" BorderBrush="LightGray" CornerRadius="3" BorderThickness="1" Margin="0" Padding="0">
            <DockPanel>
                <StackPanel DockPanel.Dock="Top">
                    <DockPanel Margin="0"  HorizontalAlignment="Stretch">
                        <ComboBox ItemsSource="{Binding Sources}" Margin="2"
                              SelectedIndex="{Binding SourceIndex}"
                              Padding="6" Width="70" FontSize="10" DockPanel.Dock="Left" x:Name="cmbSource"/>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"></ColumnDefinition>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <Border CornerRadius="4" Grid.Column="0" Margin="1" BorderThickness="2" BorderBrush="LightGray">
                                <TextBox x:Name="txtMain"  Text="{Binding Input,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" KeyDown="txtMain_KeyDown"
                                 VerticalAlignment="Stretch" GotFocus="txtMain_GotFocus" LostFocus="txtMain_LostFocus" ></TextBox>
                            </Border>
                            <Button Content=" Go " Command="{Binding SearchCommand}" Width="30" Margin="2" Grid.Column="2"/>
                        </Grid>

                    </DockPanel>
                    <ProgressBar Padding="1" Visibility="{Binding IsLoading}"  Height="14" Margin="3" IsIndeterminate="True" />
                    <Expander Margin="3" Background="Red" Foreground="White" Header="Errors Found During Search" Visibility="{Binding HasErrors}">
                        <TextBlock Padding="2" TextWrapping="Wrap" Foreground="White" Text="{Binding Errors}"/>
                    </Expander>
                </StackPanel>
                <Grid >
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <Grid  Grid.Row="0">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="30"/>
                        </Grid.RowDefinitions>
                        <Border Grid.Row="0" Background="White" BorderBrush="Gray" CornerRadius="4" BorderThickness="1" Margin="3">
                            <ScrollViewer x:Name="scrollView">
                                <ItemsControl x:Name="itemsMain" Background="White"  ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
                             ItemsSource="{Binding Results}" HorizontalContentAlignment="Stretch" >
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <Border Margin="1" Padding="2" CornerRadius="4" MouseEnter="Border_MouseEnter" MouseLeave="Border_MouseLeave" BorderThickness="1">
                                                <StackPanel>
                                                    <TextBlock Text="{Binding Title}" Cursor="Hand" MouseLeftButtonDown="TextBlock_MouseLeftButtonDown" Foreground="DarkBlue" FontFamily="Arial" FontSize="12" TextWrapping="Wrap" FontWeight="Bold">
                                                        <TextBlock.ToolTip>
                                                               <ToolTip>
                                                            <StackPanel>
                                                            <TextBlock Text="Source:" FontWeight="Bold" Padding="2"/>
                                                            <TextBlock Width="220" TextWrapping="Wrap" Text="{Binding URL}" Padding="2"/>
                                                            </StackPanel>
                                                        </ToolTip>
                                                        </TextBlock.ToolTip>
                                                    </TextBlock>
                                                    <TextBlock Text="{Binding Description}" FontFamily="Arial" FontSize="11" Margin="2" TextWrapping="Wrap"></TextBlock>
                                                    <StackPanel Orientation="Horizontal" Height="22">
                                                        <StackPanel HorizontalAlignment="Right" x:Name="buttonPanel" Orientation="Horizontal" Visibility="Collapsed">
                                                            <Button Margin="2" FontSize="9" Command="{Binding OpenCommand}" Content="Open" Width="40" Height="18"/>
                                                        </StackPanel>
                                                        <TextBlock Text="{Binding Date}" FontSize="10" Foreground="Gray" Padding="4" HorizontalAlignment="Left"></TextBlock>
                                                    </StackPanel>
                                                    <Rectangle Margin="1" Height="1" Fill="LightGray"/>
                                                </StackPanel>
                                            </Border>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                            </ScrollViewer>
                        </Border>
                        <StackPanel Grid.Row="1" Margin="4" Orientation="Horizontal" HorizontalAlignment="Right">
                            <StackPanel Width="10" Margin="1"/>
                            <TextBlock Text="{Binding Offset}" Foreground="DarkBlue" FontWeight="Bold" Margin="1"/>
                            <TextBlock Text=" To " Margin="1"/>
                            <TextBlock Text="{Binding OffsetEnd}" Foreground="DarkBlue" FontWeight="Bold" Margin="1"/>
                            <TextBlock Text=" Of " Margin="1"/>
                            <TextBlock Text="{Binding Total}" Foreground="DarkBlue" FontWeight="Bold" Margin="1"/>
                            <TextBlock Text=" Results" Margin="1"/>
                            <StackPanel Width="10" Margin="2"/>
                            <Button Content="&lt;&lt; Prev" Command="{Binding PrevCommand}"></Button>
                            <StackPanel Width="5" Margin="2"/>
                            <Button Content="Next &gt;&gt;" Command="{Binding NextCommand}"></Button>
                        </StackPanel>
                    </Grid>
                </Grid>
            </DockPanel>
        </Border>



    </Grid>
</UserControl>
